﻿namespace DeltaGroup.WheelOfJeopardy.UI.ViewModel
{
    using System.ComponentModel;

    public class NewContestantModel : BaseViewModel, IDataErrorInfo
    {
        #region Fields

        private int _index;
        private string _name;

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="NewContestantModel"/> class.
        /// </summary>
        /// <param name="index">The index.</param>
        public NewContestantModel(int index)
        {
            _index = index;
            Name = "";
        }

        #endregion Constructors

        #region Properties

        /// <summary>
        /// Gets an error message indicating what is wrong with this object.
        /// </summary>
        /// <value></value>
        /// <returns>An error message indicating what is wrong with this object. The default is an empty string ("").</returns>
        public string Error
        {
            get { return null; }
        }

        /// <summary>
        /// Gets or sets the index.
        /// </summary>
        /// <value>The index.</value>
        public int Index
        {
            get { return _index; }
            set
            {
                _index = value;
                FirePropertyChanged("Index");
            }
        }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name.</value>
        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                FirePropertyChanged("Name");
            }
        }

        #endregion Properties

        #region Indexers

        /// <summary>
        /// Gets the <see cref="System.String"/> with the specified column name.
        /// </summary>
        /// <value></value>
        public string this[string columnName]
        {
            get
            {
                return columnName == "Name" && string.IsNullOrEmpty(Name.Trim())
                           ? string.Format("Please enter a name for contestant {0}", Index)
                           : null;
            }
        }

        #endregion Indexers
    }
}